﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
using Control_Searcher;
using Language_Editor;
using System.Configuration;
using System.Data.Linq;
using BLL;
using TestWinform;
using Microsoft.Build.Construction;
using System.IO;

using BE;

using SearchControls;
using Telerik.WinControls.UI;
using System.Configuration;
using System.Windows.Forms;

namespace LocalTest
{
    
    class Program
    {
        
        [STAThread]
        static void Main(string[] args)
        {
            defaultValueTest();
        }

        private static void defaultValueTest()
        {
            Console.WriteLine(languageConnector.getDefaultLanguage().Name);
        }

        private static void dictionaryReturnTest()
        {
            Dictionary<string, bool> list = languageConnector.getSaveList();
            foreach (KeyValuePair<string, bool> pair in list)
            {
                Console.WriteLine(pair.Key+" - "+pair.Value);
            }
        }

        private static void CopyDirectoryTest()
        {
            Console.WriteLine("Copying...");
            CopyDirectory(@"C:\conf\WebSite", @"C:\conf\ttte", true);
        }
        private static bool CopyDirectory(string SourcePath, string DestinationPath, bool overwriteexisting)
        {
            bool ret = false;
            try
            {
                SourcePath = SourcePath.EndsWith(@"\") ? SourcePath : SourcePath + @"\";
                DestinationPath = DestinationPath.EndsWith(@"\") ? DestinationPath : DestinationPath + @"\";

                if (Directory.Exists(SourcePath))
                {
                    if (Directory.Exists(DestinationPath) == false)
                        Directory.CreateDirectory(DestinationPath);

                    foreach (string fls in Directory.GetFiles(SourcePath))
                    {
                        FileInfo flinfo = new FileInfo(fls);
                        flinfo.CopyTo(DestinationPath + flinfo.Name, overwriteexisting);
                    }
                    foreach (string drs in Directory.GetDirectories(SourcePath))
                    {
                        DirectoryInfo drinfo = new DirectoryInfo(drs);
                        if (CopyDirectory(drs, DestinationPath + drinfo.Name, overwriteexisting) == false)
                            ret = false;
                    }
                }
                ret = true;
            }
            catch (Exception ex)
            {
                ret = false;
            }
            return ret;
        }  
        private static void stringPlaceHolderTest()
        {
            StringPlaceHolder s = new StringPlaceHolder(2, "name");
            Console.WriteLine(s);
        }

        private static void classTest()
        {
            testClass t = new testClass("parameter");
        }
        private class testClass
        {
            public testClass(string test) : this()
            {
                Console.WriteLine(test);
            }

            public testClass()
            {//denne bliver kaldt før den med en parameter når man laver en : this() på constructoren
                Console.WriteLine("parameterless");
            }
        }
       

        private static void sqlTest()
        {
            Console.WriteLine(languageConnector.IsTablesInDb().ToString());
        }

        private static void configTest()
        {
            //Console.WriteLine("trying with =");
            Configuration c = ConfigurationManager.OpenExeConfiguration("LanguageApp.exe");
            Console.WriteLine(c.AppSettings.Settings["VariableName"].Value);
            //c.AppSettings.Settings["test"].Value = "newValue";
            //c.Save();
            //string[] conf;
            
           // conf = File.ReadAllLines(@"C:\Users\hbabb\Documents\Visual Studio 2010\Projects\Language Editor\LocalTest\bin\Debug\LocalTest.exe.config");
             //   foreach(string s in conf)
               //     Console.WriteLine(s);
           
        }

        

        private static void CultureInfoTest()
        {
            CultureInfo c = new CultureInfo("en-GB");
            c.ToString();
        }

        private static void SortedDictionaryTest()
        {
            SortedDictionary<int, string> d = new SortedDictionary<int, string>();
            d.Add(4, "four");
            d.Add(3, "three");
            d.Add(30,"thirty");
            d.Add(2, "two");
            d.Add(1, "one");
                Console.WriteLine(d.Last());
            Console.WriteLine(d.Keys.Last());
            Console.WriteLine(d.Values.Last());
        }

        private static void ObjectTest()
        {
            TestForm t = new TestForm();
            RadGridView g = t.getMyControl();
            Console.WriteLine(t.GetType());
            foreach (GridViewColumn c in g.Columns)
            {
                Console.WriteLine("getType: " + c.GetType() + " |###|Name: " + c.Name + " |###| UniqueName: " + c.UniqueName);
            }
        }

        
        private static void ClassParsertest()
        {
            List<string> list = ClassParser.findFormNames(@"C:\Users\hbabb\Documents\Visual Studio 2010\Projects\Language Editor\WinMenu\Form1.cs");
            foreach (string s in list )
            {
                Console.WriteLine(s);
            }
        }
        private static void indexTest()
        {
            string search = "abaaba";
            int a = search.IndexOf('a',0);
            int b = search.IndexOf('a',a+1);
            int c = search.IndexOf('a',b+1);
            int d = search.IndexOf('a',c+1);
            Console.WriteLine(""+a+" "+b+" "+c+" "+d);
        }
        private static void projects()
        {
            string current = Directory.GetCurrentDirectory();
            string debug = Directory.GetParent(current).FullName;
            string proj = Directory.GetParent(debug).FullName;
            string sol = Directory.GetParent(proj).FullName;
            Console.WriteLine(sol);
            Solution mysolution = new Solution(@"C:\Users\hbabb\Documents\Visual Studio 2010\Projects\Language Editor\Language Tool.sln");
            foreach (SolutionProject p in mysolution.Projects)
            {
                Console.WriteLine("##########\nFiles for: " + p.ProjectName + "\n##########");
                //Console.WriteLine(p.RelativePath);
                //string[] files = Directory.GetFiles(new FileInfo(sol + "\\" + p.RelativePath).DirectoryName,"*.cs");
                DirectoryInfo ProjectDir = new FileInfo(sol + "\\" + p.RelativePath).Directory;
                    FileInfo[] fi = ProjectDir.GetFiles();
                foreach(FileInfo file in fi)
                {
                Console.WriteLine(file.Name);
                }
                Console.WriteLine();
            }
            
        }

        

private static void gettexts(bool save)
{
    ReadInfo r = new ReadInfo();
 	//r.forms.Add(new LanguageEditor());
    //r.forms.Add(new NewElement());
    //r.forms.Add(new PickLanguage());

    r.forms.Add(new TestForm());
    r.forms.Add(new Testform2());
    r.forms.Add(new winform());
    r.forms.Add(new wizardtestform());
    r.saveAllTexts();
    string[] lines = new string[r.texts.Count];
    int i = 0;
    foreach (ControlInfo c in r.texts.Values)
    {
        lines[i] = c.Text;
        i++;
    }
    System.IO.File.WriteAllLines(@"C:\conf\controls.txt", lines);
    if (save)
        r.SaveToDb();
}

        private static void callsqlmetal()
        {
            Process p= new Process();
p.StartInfo.WorkingDirectory = @"C:\whatever";
p.StartInfo.FileName = @"C:\some.exe";
p.StartInfo.CreateNoWindow = true;
            p.StartInfo.Arguments = "";
p.Start();
p.WaitForExit();
        }
    }
}
